Skip to content

Fix flaky RecompileScripts examples caused by a delayed domain reload - #46

Merged
nowsprinting merged 3 commits into
masterfrom
fix/recompile-scripts-example
Nov 7, 2026
Merged

nowsprinting merged 3 commits into
masterfrom
fix/recompile-scripts-example

Conversation

@nowsprinting

@nowsprinting nowsprinting commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Problem

RecompileScriptsでリコンパイルを実行する例_リコンパイルされたクラスのメソッドを呼び出せる intermittently fails on CI with MissingMethodException: Default constructor not found for type Foo (seen on Unity 6000.3.18f1 and 6000.5.1f1).

Trigger Conditions

It runs right after ..._csc_rspで追加したスクリプティングシンボルが有効になる (added in e28f85f), whose TearDown deletes csc.rsp.
The next RecompileScripts then recompiles every assembly.

Root Cause

RecompileScripts waits only until EditorApplication.isCompiling becomes false; it does not wait for the domain reload.
The reload usually completes before the test resumes, but sometimes it is still pending (the log shows domain reloads=0 for that refresh).
The test then reflects on the old Assembly-CSharp, which still holds the static class Foo from the previous test.

Solution

  • After RecompileScripts, wait on a static flag set before the yield. Static fields reset on domain reload, so the flag shows whether the reload has happened yet.
    • Not WaitForDomainReload: it throws when the reload has already completed inside RecompileScripts, which is the usual case.
    • Not InternalEditorUtility.IsScriptReloadRequested(): it is internal.
  • Create the generated script and csc.rsp under Assets/APIExamples/Scripts/Runtime instead of Assets/, so that only the APIExamples assembly is recompiled. The csc_rsp test takes 4–9 s instead of 27–49 s.
  • Also includes the CI Unity version upgrade (b77fdb8).

Verification

  • Five CI reruns across all six Unity versions passed, but the delayed reload did not occur in any of them, so CI has not exercised the wait.
  • Locally on 6000.0.43f1, the delayed reload occurred once (reload requested but not yet done right after RecompileScripts), so it is not specific to Unity 6.3 and later.

🤖 Generated with Claude Code

nowsprinting and others added 2 commits November 8, 2026 05:24
RecompileScripts returns once compilation finishes, but the domain reload
can still be pending; the test then resumes on the old assemblies and fails
(seen on CI with Unity 6.3 and 6.5, and locally with 6.0).
Wait until the reload actually happens, and log the reload state so CI runs
show whether the delay occurred.

Create the generated script and csc.rsp under the APIExamples assembly
instead of Assets/ so that only that assembly is recompiled, not every
assembly in the project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

The logging was added to see whether the delayed domain reload occurs on CI.
Five reruns across all Unity versions never showed it, so the log no longer
earns its noise; the wait itself stays as a safeguard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nowsprinting nowsprinting changed the title Fix problem where tests using RecompileScripts would fail in Unity 6.3 Fix flaky RecompileScripts examples caused by a delayed domain reload Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Code Metrics Report

master (e28f85f) #46 (66192af) +/-
Coverage 39.0% 39.0% 0.0%
Code to Test Ratio 1:4.0 1:4.0 +0.0
Test Execution Time 8m34s 5m40s -2m54s
Details
  |                     | master (e28f85f) | #46 (66192af) |  +/-   |
  |---------------------|------------------|---------------|--------|
  | Coverage            |            39.0% |         39.0% |   0.0% |
  |   Files             |               25 |            25 |      0 |
  |   Lines             |              476 |           476 |      0 |
  |   Covered           |              186 |           186 |      0 |
+ | Code to Test Ratio  |            1:4.0 |         1:4.0 |   +0.0 |
  |   Code              |             1256 |          1255 |     -1 |
+ |   Test              |             5111 |          5125 |    +14 |
+ | Test Execution Time |            8m34s |         5m40s | -2m54s |

Reported by octocov

@nowsprinting
nowsprinting marked this pull request as ready for review November 7, 2026 23:07
@nowsprinting
nowsprinting merged commit 88a510e into master Nov 7, 2026
14 checks passed
@nowsprinting
nowsprinting deleted the fix/recompile-scripts-example branch November 7, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant